﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyDelegateDemo
{
    public class MyRichardExtend
    {
        public void Show()
        {
            Console.WriteLine("欢迎来到.NET 高级班的体验课~");
        }
    }


    public class MyDelegateRichardExtend
    { 
        public List<Func<Action,Action>> actionList = new List<Func<Action, Action>>();

        public void Show()
        { 
            //这里是要执行的核心业务逻辑
            MyRichardExtend myRichardExtend = new MyRichardExtend();
            //定义一个委托
            Action action = () => { myRichardExtend.Show(); };

             
            Action<Action> actionResult = null;

            foreach (var item in actionList)
            {
                action= item.Invoke(action);
            } 
             
            //循环完毕后, action变成了多层嵌套的委托; 
            action.Invoke();  //最后这一步执行---就是要去执行多层嵌套的委托---俄罗斯套娃;

        }
    }
}
